package com.woniuxy.woniuhis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.woniuhis.entity.Repository;
import com.woniuxy.woniuhis.exception.MedicineServiceException;
import com.woniuxy.woniuhis.mapper.MedicineMapper;
import com.woniuxy.woniuhis.mapper.RepositoryMapper;
import com.woniuxy.woniuhis.service.RepositoryService;

@Service
public class RepositoryServiceImpl implements RepositoryService {

	@Autowired
	MedicineMapper medicineMapper;

	@Autowired
	RepositoryMapper repositoryMapper;

	/*
	 * //通过药物名字找到库存
	 */
	@Override
	public List<Repository> findRepositoryByMediName(Repository repository) {

		try {
			List<Repository> reps = repositoryMapper.selectRepositoryByMediName(repository);
			return reps;
		} catch (Exception e) {
			System.out.println("findRepositoryByMediName错误");
			e.printStackTrace();
			throw new MedicineServiceException("findRepositoryByMediName错误");
		}
	}

	@Override
	public void updateRepositoryByPharIdAndMediId(Repository repository) {
		try {
			repositoryMapper.updateIncrementStock(repository);
		} catch (Exception e) {
			System.out.println("updateRepositoryByPharIdAndMediId错误");
			e.printStackTrace();
			throw new MedicineServiceException("updateRepositoryByPharIdAndMediId错误");
		}
	}

}
